'use strict';

goog.provide('Blockly.Blocks.storer');
goog.require('Blockly.Blocks');

Blockly.Msg['STORER_HUE'] = 0;

Blockly.Blocks.xnr_EEPROM_write_put = {
    init: function() {
        this.appendValueInput("NAME")
            .setCheck(null)
            .appendField("写入  EEPROM")
            .appendField(new Blockly.FieldDropdown([
                ["多字节", "put"],
                ["单字节", "write"]
            ]), "read_get")
            .appendField("地址");
        this.appendValueInput("DATA")
            .setCheck(null)
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField("数据");
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(Blockly.Msg['STORER_HUE']);
        this.setTooltip("勾选加载头文件，EEPROM.write()函数每次只能写入一个字节的数据到EEPROM，EEPROM.put()函数允许我们向EEPROM写入多字节的数据");
        this.setHelpUrl("");
    }
};

Blockly.Blocks.xnr_EEPROM_get = {
    init: function() {
        this.appendValueInput("NAME")
            .setCheck(null)
            .appendField("读取多字节EEPROM")
            .appendField("地址");
        this.appendValueInput("DATA")
            .setCheck(null)
            .setAlign(Blockly.ALIGN_RIGHT)
            .appendField("保存到 变量");
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(Blockly.Msg['STORER_HUE']);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

Blockly.Blocks.xnr_EEPROM_read_get = {
    init: function() {
        this.appendValueInput("NAME")
            .setCheck(null)
            .appendField("读取EEPROM")
            .appendField("地址:变量");
        this.setOutput(true, null);
        this.setColour(Blockly.Msg['STORER_HUE']);
        this.setTooltip("EEPROM.read()函数每次只能读取一个字节的数据。EEPROM.get()函数允许用户一次获取多个字节的数据。");
        this.setHelpUrl("");
    }
};

Blockly.Blocks.xnr_EEPROM_begin = {
    init: function() {
        this.appendDummyInput()
            .appendField("申请内存")
            .appendField(new Blockly.FieldTextInput("512"), "size")
            .appendField("字节");
        this.setInputsInline(true);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(Blockly.Msg['STORER_HUE']);
        this.setTooltip("调用EEPROM.begin(size)，开辟大小为size的空间，取值4~4096");
        this.setHelpUrl("");
    }
};

Blockly.Blocks.xnr_EEPROM_commit = {
    init: function() {
        this.appendDummyInput()
            .appendField("写入flash");
        this.setInputsInline(true);
        this.setOutput(true, null);
        this.setColour(Blockly.Msg['STORER_HUE']);
        this.setTooltip("EEPROM.commit()把内存空间的数据覆盖到flash eeprom块去   参数： 无； 返回值： 返回bool值，表示是否覆盖成功；");
        this.setHelpUrl("");
    }
};

Blockly.Blocks.xnr_EEPROM_end = {
    init: function() {
        this.appendDummyInput()
            .appendField("写入flash并释放内存");
        this.setInputsInline(true);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(Blockly.Msg['STORER_HUE']);
        this.setTooltip("EEPROM.end()包含了写入flash，并且回收内存空间 建议读者操作完EEPROM之后，必须调用这个方法，回收内存空间很重要");
        this.setHelpUrl("");
    }
};

Blockly.Blocks.xnr_EEPROM_lianjie = {
    init: function() {
        this.appendValueInput("NAME")
            .setCheck(null)
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(Blockly.Msg['STORER_HUE']);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};